#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include "zmalloc.h"
#include "queue.h"					  /* use the SimCList library */
#include "graph.h"					  /* use the SimCList library */


int main(int argc,char **argv)
{
        Queue *queue;
	Graphs *mygraph;  /* declare a graph */
	Graph_node *xnode,*ynode;
	int userval;
	int i,cnt,*rnum;


        if ( argc < 2 )  {
	 printf("Usage: %s <count>\n",argv[0]);
	 exit(0);
        }

	mygraph = graph_create(0,0,0);  /* initialize the graph */

	userval = atol(argv[1]);

	queue = initQueue();

   for ( i = 0 ; i < userval ; i++ ) {

	xnode = graph_node_create();

	rnum = zcalloc(sizeof(int));
	*rnum = randi(10000);
	xnode->value = rnum;
	enqueue(queue,(void *)xnode);
	
        cnt = randi(10);
	if ( ( listLength((list *)queue )<1000 ) && ( cnt > 3 ) ) continue;

	ynode = (Graph_node *)dequeue(queue);
	if( ( ynode == NULL ) || (ynode->value == NULL ) )continue;

	printf("%d %d devalue %d\n",listLength((list *)queue),isQueueFull(queue),*(int *)ynode->value);

        graph_node_release(ynode,zfree,zfree);

	}

	//for (i = 0; i<userval ; rnum=randi(userval), i++)
	//	graphAddNodeTail(mygraph, &rnum);	/* add an element to the graph */

//	printf("The graph now holds %lu elements.\n", graphLength(mygraph));	/* get the size of the graph */

	graph_release(mygraph);

	return 0;
}
